package com.xiashitech.agent.instrumentation.httprequest.filter;

import com.xiashitech.agent.dto.UserRequest;
import com.xiashitech.agent.instrumentation.httprequest.XSHttpRequestAttributesExtractor;
import io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.Instrumenter;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.api.GlobalOpenTelemetry;

import javax.servlet.ServletResponse;

public class XSRequestSingletons {
    private XSRequestSingletons() {}
    private static final String INSTRUMENTATION_NAME = "com.xiashitech.http-filter";
    private static final String SPAN_NAME = "xs.http-filter-span";
    private static final Instrumenter<UserRequest, ServletResponse> INSTRUMENTER;
    public static Instrumenter<UserRequest, ServletResponse> instrumenter() {
        return INSTRUMENTER;
    }

    static {
        INSTRUMENTER =
                Instrumenter.<UserRequest, ServletResponse>builder(
                                GlobalOpenTelemetry.get(),
                                INSTRUMENTATION_NAME,
                                request -> SPAN_NAME
                        ).addAttributesExtractor(new XSHttpRequestAttributesExtractor())
                        .buildInstrumenter();
    }
}
